<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="/html/js/axios.min.js"></script>
    <script src="/html/js/ajax.js"></script>
    <script>
        window.onload = function (){
            findByItem(1);
        }

        //动态条件查询
       async function  findByItem(pageNO){
            var param = {pageNO:pageNO,
                name:$("name").value,
                startDate:$("startDate").value,
                endDate:$("endDate").value,
            };

            var info = await ajaxGet("/employee/findByItem",param);
            var str = "";
            for(var i=0;i<info.list.length;i++){
                var obj = info.list[i];
                str += `<tr><td>${obj.name}</td><td>${obj.birthday}</td>
                <td>${obj.money}</td><td>${obj.dept.name}</td><td>
                <a href="javascript:del(${obj.id})">删除</a>
                <a href="/html/update.html?id=${obj.id}">修改</a></td></tr>`;
            }
            $("data").innerHTML = str;

            var cutStr = "";
            for(var i=1;i<=info.pages;i++){
                cutStr += `<a style="margin-left: 10px"
                    href="javascript:findByItem(${i})">${i}</a>`;
            }
            $("cutPageDiv").innerHTML = cutStr;
        }

        //删除
        async function del(id){
             var info = await ajaxGet("/employee/del",{id});
             if(info == "ok"){
                 findByItem(1);
             }
             else{
                 alert("删除失败");
             }
        }
    </script>
</head>
<body>

    <table border="1" cellspacing="0" width="60%">
        <thead><tr><th>姓名</th><th>生日</th><th>工资</th><th>部门</th><th>操作</th></tr></thead>
        <tbody id="data"></tbody>
    </table>
    <div id="cutPageDiv"></div>
    <div><a href="/html/add.html">添加</a></div>
    <div>
        姓名：<input type="text" id="name"><br>
        起始日期：<input type="text" id="startDate"><br>
        结束日期：<input type="text" id="endDate"><br>
        <input type="button" onclick="findByItem(1)" value="查询">
    </div>

</body>
</html>